package com.ld.admin.service.system.dbbackup;

import java.util.HashMap;
import java.util.Map;

import com.ld.admin.model.system.dbbackup.DbBackupSetModel;
import com.ld.admin.service.system.dbbackup.impl.DbBackUpHandler;
import com.ld.admin.service.system.dbbackup.impl.DbBackupStructureHandler;
import com.ld.admin.service.system.dbbackup.impl.DbbackUpAllHandler;
import com.ld.admin.service.system.dbbackup.impl.DbbackupDataHandler;
import com.ld.shieldsb.common.core.util.StringUtils;

public class BbBackUpFactory {

    public static final Map<String, DbBackUpHandler> DBBACKUP_HANDLER_MAP = new HashMap<>();

    static {
        DBBACKUP_HANDLER_MAP.put("default", new DbbackUpAllHandler()); // 默认备份所有
        DBBACKUP_HANDLER_MAP.put("data", new DbbackupDataHandler());// 备份数据
        DBBACKUP_HANDLER_MAP.put("structure", new DbBackupStructureHandler());// 备份结构
        DBBACKUP_HANDLER_MAP.put("all", new DbbackUpAllHandler()); // 默认备份所有
    }

    public static void backupDb() {
        backupDb(null);
    }

    public static void backupDb(DbBackupSetModel backupSetModel) {
        DbBackUpHandler dbHandler = null;
        if (StringUtils.isEmpty(backupSetModel.getDbHandler())) {
            dbHandler = DBBACKUP_HANDLER_MAP.get("default");
        } else {
            dbHandler = DBBACKUP_HANDLER_MAP.get(backupSetModel.getDbHandler());
        }
        if (dbHandler == null) {
            dbHandler = DBBACKUP_HANDLER_MAP.get("default");
        }
        dbHandler.dbbackup(backupSetModel);
    }

}
